﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DynaPrecision.RandomNumberGenerator
{
	public class Gauss<T> : IRandomNumberGenerator<T>
	{
		public Gauss()
		{
			this.Mean = DefaultValueProvider<T>.Zero;
			this.Sigma = DefaultValueProvider<T>.GetValueFromInteger(1);
		}
		public T Mean { get; set; }
		public T Sigma { get; set; }
		public T Next()
		{
			double result = Math.Sqrt(-2.0 * Math.Log(SingletonUniformRandomProvider.NextDouble())) * Math.Cos(2 * Math.PI * SingletonUniformRandomProvider.NextDouble());
			result = result * (dynamic)Sigma;
			result = result + (dynamic)Mean;
			return DefaultValueProvider<T>.GetValueFromDouble(result);
		}
	}
}
